package com.yegs.jindie.serviceImpl;

import com.yegs.jindie.entity.UserConfigTO;
import com.yegs.jindie.repository.UserConfigRepository;
import com.yegs.jindie.service.UserConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserConfigServiceImpl implements UserConfigService {

    @Autowired
    private UserConfigRepository userConfigRepository;

    @Override
    public boolean save(UserConfigTO userConfigTO) {
        try {
            UserConfigTO userConfig = this.getUserConfig();
            userConfigTO.setId(userConfig.getId());
            userConfigRepository.save(userConfigTO);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public UserConfigTO getUserConfig() {
        List<UserConfigTO> all = userConfigRepository.findAll();
        if(all == null ||all.size() == 0){
            return null;
        }else{
            return all.get(0);
        }
    }
}
